<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 引入人家依赖 -->
    <script src='./js/swiper.js'></script>
    <link rel="stylesheet" href="./css/swiper.css">
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .swiper-container {
            width: 800px;
            height: 400px;
            margin: 50px auto;
            border: 1px solid black;
        }
    </style>
</head>

<body>
    <!-- 添加HTML内容。Swiper7的默认容器是'.swiper'，Swiper6之前是'.swiper-container'。 -->
    <!-- 你想使用人家轮播图功能:静态结构必须完整 -->
    <div class="swiper-container">
        <div class="swiper-wrapper">
            <div class="swiper-slide">Slide 1</div>
            <div class="swiper-slide">Slide 2</div>
            <div class="swiper-slide">Slide 3</div>
        </div>
        <!-- 如果需要分页器 -->
        <div class="swiper-pagination"></div>

        <!-- 如果需要导航按钮 -->
        <div class="swiper-button-prev"></div>
        <div class="swiper-button-next"></div>

        <!-- 如果需要滚动条 -->
        <div class="swiper-scrollbar"></div>
    </div>
</body>

</html>
<script>
    //swiper插件:对外暴露一个Swiper构造函数【如果你想给轮播图添加动态效果，初始化这个类的实例】
    //Swiper配置项:第一个参数根节点DOM
    //第二个参数:配置项，你不能瞎写、胡写、乱写
    let sp = new Swiper(document.querySelector('.swiper-container'), {
        //开启循环模式
        loop: true,
        //设置轮播图水平方向
        direction: 'horizontal',//horizontal 水平   vertical 垂直
        //前进与后退按钮的配置项
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },
        //分页器
        pagination: {
            el: '.swiper-pagination',
            //分页器类型
            // type:'fraction'
            //点小球也会动
            clickable :true,
        },
        //自动轮播
        autoplay: {
            //自动播放事件
            delay: 1000,
            //如果设置为true，当切换到最后一个slide时停止自动切换。（loop模式下无效）。
            stopOnLastSlide: true,
            //点击左右按钮轮播图就停下来
            disableOnInteraction: true,
        },
    });
    //鼠标进入
    sp.el.onmouseover = function () {
        sp.autoplay.stop();
    }
    //鼠标离开
    sp.el.onmouseout = function () {
        sp.autoplay.start();
    }



</script>